package site.weiyikai.eventdriven.core;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;


/**
 * 描述：
 *
 * @author 程序员小魏
 * 创建时间: 2023/11/06
 */
public class DaemonThreadFactory implements ThreadFactory{

    private final AtomicInteger threadNumber = new AtomicInteger(1);
    private final String namePrefix;
    public DaemonThreadFactory(final String namePrefix) {
        this.namePrefix = namePrefix;
    }

    @Override
    public Thread newThread(Runnable r) {
        final Thread thread;
        thread = new Thread(r);
        thread.setDaemon(true);
        thread.setName(namePrefix + "-thread-" + threadNumber.getAndIncrement());
        return thread;
    }
}
